package com.example.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.springframework.beans.factory.annotation.Autowired;

import com.example.service.SsoMemberService;
import com.example.util.SsoUtil;

@WebListener
public class RequestListener implements HttpSessionListener {
	
	@Autowired
	private SsoMemberService ssoMemberService;

	@Override
	public void sessionCreated(HttpSessionEvent se) {
          HttpSession session = se.getSession();
          String id = session.getId();
          System.out.println("sso-sever，创建session,id为："+id);
		
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		  HttpSession session = se.getSession();
          String id = session.getId();
          System.out.println("sso-sever，销毁session,id为："+id);
          //销毁token，通知当前用户已登录的服务器，销毁局部会话
        String username= session.getAttribute("username")==null?"":session.getAttribute("username").toString();
        String logout = SsoUtil.notifyMembersToLogout(username,ssoMemberService);
        
		
	}





}
